package externalflame.systemdesign.secondkill.controller;

import externalflame.systemdesign.secondkill.dto.OrderDto;
import externalflame.systemdesign.secondkill.entity.Order;
import externalflame.systemdesign.secondkill.exception.NoStockException;
import externalflame.systemdesign.secondkill.exception.NoSuchSecKillException;
import externalflame.systemdesign.secondkill.exception.NotValidPeriodException;
import externalflame.systemdesign.secondkill.exception.PerPurchaseLimitException;
import externalflame.systemdesign.secondkill.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "订单")
@RestController
@RequestMapping("orders")
public class OrderController {

    @Autowired
    OrderService orderService;

    @ApiOperation("下单")
    @PostMapping(value = "/")
    public Order placeOrder(@RequestHeader Long userId, @RequestBody OrderDto orderDto) throws NotValidPeriodException, NoSuchSecKillException, PerPurchaseLimitException, NoStockException {
        return orderService.add(userId, orderDto);
    }
}
